'''Track instances of Panel objects'''

import weakref

class PanelTracker(dict):
    '''Used to track panels

    This is essentiallly a dict, where the keys are a tuple
    made up of a window and a panel id.

    '''

    def forget(self, target_panel):
        '''Remove a panel from the tracker
        '''
        target_key = None
        for (key, panel_weakref) in self.iteritems():
            panel = panel_weakref()
            if target_panel == panel:
                target_key = key
        if target_key:
            self.pop(target_key)

    def track(self, panel):
        '''Add a panel to the tracker'''
        key = (panel.GetTopLevelParent(),panel._id)
        self.setdefault(key, weakref.ref(panel))
        
        
